<!DOCTYPE html>

<head>
    <meta charset="UTF-8">
    <title>搜索</title>
    <meta name="author" content="邢栋">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="renderer" content="webkit" />
    <meta name="force-rendering" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <script>/*@cc_on window.location.href="https://support.dmeng.net/upgrade-your-browser.html?referrer="+encodeURIComponent(window.location.href); @*/</script>
</head>

<body>
    <a href="https://github.com/xclala/search">
        <img src="../github.svg">
    </a>
    <h1>搜索</h1>
    <a href="..">🔙<br></a>
    <p></p>
    <a href="qrcode.png">二维码</a>
    <script>
        function baidu() {
            setCookie("search", document.forms["form"]["text"].value, 365)
            window.open("https://www.baidu.com/s?wd=" + encodeURI(document.forms["form"]["text"].value))
        }

        function bing() {
            setCookie("search", document.forms["form"]["text"].value, 365)
            window.open("https://cn.bing.com/search?q=" + encodeURI(document.forms["form"]["text"].value))
        }

        function ecosia() {
            setCookie("search", document.forms["form"]["text"].value, 365)
            window.open("https://www.ecosia.org/search?q=" + encodeURI(document.forms["form"]["text"].value))
        }

        function sogo() {
            setCookie("search", document.forms["form"]["text"].value, 365)
            window.open("https://www.sogou.com/web?query=" + encodeURI(document.forms["form"]["text"].value))
        }

        function search_360() {
            setCookie("search", document.forms["form"]["text"].value, 365)
            window.open("https://www.so.com/s?q=" + encodeURI(document.forms["form"]["text"].value))
        }

        function zhihu() {
            setCookie("search", document.forms["form"]["text"].value, 365)
            window.open("https://www.zhihu.com/search?q=" + encodeURI(document.forms["form"]["text"].value))
        }

        function bilibili() {
            setCookie("search", document.forms["form"]["text"].value, 365)
            window.open("https://search.bilibili.com/all?keyword=" + encodeURI(document.forms["form"]["text"].value))
        }

        function github() {
            setCookie("search", document.forms["form"]["text"].value, 365)
            window.open("https://github.com/search?q=" + encodeURI(document.forms["form"]["text"].value))
        }

        function baidu_baike() {
            setCookie("search", document.forms["form"]["text"].value, 365)
            window.open("https://baike.baidu.com/item/" + encodeURI(document.forms["form"]["text"].value))
        }

        function gitee() {
            setCookie("search", document.forms["form"]["text"].value, 365)
            window.open("https://search.gitee.com/?q=" + encodeURI(document.forms["form"]["text"].value))
        }

        function setCookie(cname, cvalue, exdays) {
            let d = new Date();
            d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
            let expires = "expires=" + d.toGMTString();
            document.cookie = cname + "=" + cvalue + "; " + expires;
        }

        function getCookie(cname) {
            let name = cname + "=";
            let ca = document.cookie.split(';');
            for (let i = 0; i < ca.length; i++) {
                let c = ca[i].trim();
                if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
            }
            return "";
        }

        window.onload = function () {
            if (getCookie("search") != "") {
                document.forms["form"]["text"].value = getCookie("search")
            }
        }
    </script>
    <form align="center" name="form">
        <button type="reset" onclick="document.cookie='search=;expires=Thu, 01 Jan 1970 00:00:00 GMT;'">清空</button>
        <input type="text" autofocus="true" name="text">
        <input type="button" onclick="baidu()" value="百度">
        <input type="button" onclick="bing()" value="Bing">
        <input type="button" onclick="ecosia()" value="ecosia">
        <input type="button" onclick="sogo()" value="搜狗">
        <input type="button" onclick="search_360()" value="360">
        <input type="button" onclick="baidu_baike()" value="百度百科">
        <input type="button" onclick="zhihu()" value="知乎">
        <input type="button" onclick="bilibili()" value="哔哩哔哩">
        <input type="button" onclick="github()" value="github">
        <input type="button" onclick="gitee()" value="gitee">
    </form>
    <style>
        html {
            -moz-osx-font-smoothing: grayscale;
            -webkit-font-smoothing: antialiased;
            text-rendering: optimizeLegibility;
        }

        h1 {
            text-align: center;
        }

        @media(prefers-color-scheme:dark) {
            body {
                background-color: rgb(35, 35, 35);
            }

            h1 {
                color: orangered;
            }
        }

        @media(prefers-color-scheme:light) {
            body {
                background-color: wheat;
            }

            h1 {
                color: black;
            }
        }

        a {
            text-decoration-line: none;
        }

        a:hover {
            font-weight: bolder;
        }

        input {
            margin-left: 10px;
        }
    </style>
    <script>
        const BACKGROUNDCOLOR = ['rgb(35, 35, 35)', 'wheat']
        const TITLECOLOR = ['orangered', 'black']
        let a = 0
        document.getElementsByTagName("h1")[0].onclick = function () {
            document.body.style.backgroundColor = BACKGROUNDCOLOR[a % 2]
            document.getElementsByTagName("h1")[0].style.color = TITLECOLOR[a % 2]
            a++
        }
    </script>
</body>